class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}

class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        return dfs(list1,list2);
    }
    public ListNode dfs(ListNode list1, ListNode list2) {
        if(list1 == null) return list2;
        if(list2 == null) return list1;
        if(list1.val <= list2.val) {
            ListNode tmp = list1.next;
            list1.next = dfs(tmp,list2);
            return list1;
        }else {
            ListNode tmp = list2.next;
            list2.next = dfs(list1, tmp);
            return list2;
        }
    }
}

public class Test {
}
